\hypertarget{internal__comm_8c}{
\section{internal\_\-comm.c File Reference}
\label{internal__comm_8c}\index{internal\_\-comm.c@{internal\_\-comm.c}}
}
The internal communication routines.  


{\tt \#include $<$stdio.h$>$}\par
{\tt \#include $<$stdlib.h$>$}\par
{\tt \#include $<$avr/io.h$>$}\par
{\tt \#include $<$avr/interrupt.h$>$}\par
{\tt \#include $<$string.h$>$}\par
{\tt \#include \char`\"{}internal\_\-comm.h\char`\"{}}\par
{\tt \#include \char`\"{}internal\_\-comm\_\-rx\_\-queue.h\char`\"{}}\par
{\tt \#include \char`\"{}internal\_\-comm\_\-tx\_\-queue.h\char`\"{}}\par
\subsection*{Functions}
\begin{CompactItemize}
\item 
void \hyperlink{internal__comm_8c_038459fe5d58ddbde1ed8459d3b9bbce}{internal\_\-comm\_\-init} (void($\ast$func\_\-ptr\_\-rx)(\hyperlink{structUC__MESSAGE}{UC\_\-MESSAGE}), void($\ast$func\_\-ptr\_\-tx)(char))
\begin{CompactList}\small\item\em Initialize the internal communication. \item\end{CompactList}\item 
\hypertarget{internal__comm_8c_7db36f8f06871f98ad2effe0484aaacb}{
void \hyperlink{internal__comm_8c_7db36f8f06871f98ad2effe0484aaacb}{internal\_\-comm\_\-reset\_\-rx} (void)}
\label{internal__comm_8c_7db36f8f06871f98ad2effe0484aaacb}

\begin{CompactList}\small\item\em Will reset the RX variables. \item\end{CompactList}\item 
unsigned char \hyperlink{internal__comm_8c_64c4f318386e5cad700f6c5e08677c6f}{internal\_\-comm\_\-poll\_\-rx\_\-queue} (void)
\begin{CompactList}\small\item\em Polls the RX queue in the internal communication and calls the function defined in internal\_\-comm\_\-init. \item\end{CompactList}\item 
unsigned char \hyperlink{internal__comm_8c_35f8e503f80c8e1188ad09c1c0dde6ec}{internal\_\-comm\_\-poll\_\-tx\_\-queue} (void)
\begin{CompactList}\small\item\em Polls the TX queue in the internal communication and sends the data if there is a message in the queue. \item\end{CompactList}\item 
\hypertarget{internal__comm_8c_fbadb98b60aabeefe61ca1d21ec183db}{
void \hyperlink{internal__comm_8c_fbadb98b60aabeefe61ca1d21ec183db}{internal\_\-comm\_\-send\_\-ack} (void)}
\label{internal__comm_8c_fbadb98b60aabeefe61ca1d21ec183db}

\begin{CompactList}\small\item\em Send an ACK message to the internal communication uart. \item\end{CompactList}\item 
\hypertarget{internal__comm_8c_17a9a942903f42bd140b2cd0e2486161}{
void \hyperlink{internal__comm_8c_17a9a942903f42bd140b2cd0e2486161}{internal\_\-comm\_\-send\_\-nack} (void)}
\label{internal__comm_8c_17a9a942903f42bd140b2cd0e2486161}

\begin{CompactList}\small\item\em Send a NACK message to the internal communication uart. \item\end{CompactList}\item 
void \hyperlink{internal__comm_8c_b19320006eb32811d9c211f41e229f87}{internal\_\-comm\_\-send\_\-message} (\hyperlink{structUC__MESSAGE}{UC\_\-MESSAGE} tx\_\-message)
\begin{CompactList}\small\item\em Send a message to the internal communication uart. \item\end{CompactList}\item 
void \hyperlink{internal__comm_8c_d9191f782631f96ebe7a5d9d846ba97b}{internal\_\-comm\_\-add\_\-tx\_\-message} (unsigned char command, unsigned char length, char $\ast$data)
\begin{CompactList}\small\item\em Add a message to the transmit queue. \item\end{CompactList}\item 
\hypertarget{internal__comm_8c_37cb0731cb2b98770a5a67dfdd0303c6}{
void \hyperlink{internal__comm_8c_37cb0731cb2b98770a5a67dfdd0303c6}{internal\_\-comm\_\-resend} (void)}
\label{internal__comm_8c_37cb0731cb2b98770a5a67dfdd0303c6}

\begin{CompactList}\small\item\em Will trigger a resend of the last message. \item\end{CompactList}\item 
\hypertarget{internal__comm_8c_116f51fef6fde319f24771be58a1cd3f}{
\hyperlink{internal__comm_8c_116f51fef6fde319f24771be58a1cd3f}{ISR} (ISR\_\-INTERNAL\_\-COMM\_\-USART\_\-RECV)}
\label{internal__comm_8c_116f51fef6fde319f24771be58a1cd3f}

\begin{CompactList}\small\item\em Interrupt when a byte has been received from the UART. \item\end{CompactList}\item 
\hypertarget{internal__comm_8c_967b3989f7a8a467a717d1d294007553}{
\hyperlink{internal__comm_8c_967b3989f7a8a467a717d1d294007553}{ISR} (ISR\_\-INTERNAL\_\-COMM\_\-USART\_\-DATA)}
\label{internal__comm_8c_967b3989f7a8a467a717d1d294007553}

\begin{CompactList}\small\item\em Interrupt when data has been received from the UART. \item\end{CompactList}\item 
\hypertarget{internal__comm_8c_bfbe070c4b84a6b49bbf3db2a1d2e98d}{
void \hyperlink{internal__comm_8c_bfbe070c4b84a6b49bbf3db2a1d2e98d}{internal\_\-comm\_\-1ms\_\-timer} (void)}
\label{internal__comm_8c_bfbe070c4b84a6b49bbf3db2a1d2e98d}

\begin{CompactList}\small\item\em Function which should be called each ms. \item\end{CompactList}\end{CompactItemize}
\subsection*{Variables}
\begin{CompactItemize}
\item 
\hypertarget{internal__comm_8c_108a8e4cf1a7729812b3afadcf424cdd}{
\hyperlink{structstruct__uc__com}{struct\_\-uc\_\-com} \hyperlink{internal__comm_8c_108a8e4cf1a7729812b3afadcf424cdd}{uc\_\-com}}
\label{internal__comm_8c_108a8e4cf1a7729812b3afadcf424cdd}

\begin{CompactList}\small\item\em The uc\_\-com struct. \item\end{CompactList}\item 
\hypertarget{internal__comm_8c_b37c2abb5a019cb9a3ba7cba1e4252e6}{
\hyperlink{structUC__MESSAGE}{UC\_\-MESSAGE} \hyperlink{internal__comm_8c_b37c2abb5a019cb9a3ba7cba1e4252e6}{uc\_\-new\_\-message}}
\label{internal__comm_8c_b37c2abb5a019cb9a3ba7cba1e4252e6}

\begin{CompactList}\small\item\em Where we save any new uc\_\-comm message. \item\end{CompactList}\item 
\hypertarget{internal__comm_8c_5200fe8c22d2a9918f2ddef7b1f822bf}{
unsigned char \hyperlink{internal__comm_8c_5200fe8c22d2a9918f2ddef7b1f822bf}{prev\_\-data} = 0}
\label{internal__comm_8c_5200fe8c22d2a9918f2ddef7b1f822bf}

\begin{CompactList}\small\item\em The previous data. \item\end{CompactList}\item 
\hypertarget{internal__comm_8c_8df17071e5aaff4e53813ce271797b54}{
unsigned char \hyperlink{internal__comm_8c_8df17071e5aaff4e53813ce271797b54}{counter\_\-tx\_\-timeout} = 0}
\label{internal__comm_8c_8df17071e5aaff4e53813ce271797b54}

\begin{CompactList}\small\item\em Counter which keep track of when we last did a transmission. \item\end{CompactList}\item 
\hypertarget{internal__comm_8c_c42071d321700206caa2e1f2bb776d6f}{
unsigned char \hyperlink{internal__comm_8c_c42071d321700206caa2e1f2bb776d6f}{counter\_\-rx\_\-timeout} = 0}
\label{internal__comm_8c_c42071d321700206caa2e1f2bb776d6f}

\begin{CompactList}\small\item\em Counter which keeps track of when we last did receive a character. \item\end{CompactList}\item 
\hypertarget{internal__comm_8c_6fff055a880b6ab94f453a605e2dfea8}{
unsigned char \hyperlink{internal__comm_8c_6fff055a880b6ab94f453a605e2dfea8}{resend\_\-count} = 0}
\label{internal__comm_8c_6fff055a880b6ab94f453a605e2dfea8}

\begin{CompactList}\small\item\em The number of times the last message has been resent. \item\end{CompactList}\item 
\hypertarget{internal__comm_8c_67735c2b4d72de4b89eabd354a79c111}{
unsigned char \hyperlink{internal__comm_8c_67735c2b4d72de4b89eabd354a79c111}{msg\_\-not\_\-acked} = 0}
\label{internal__comm_8c_67735c2b4d72de4b89eabd354a79c111}

\begin{CompactList}\small\item\em Flag that the message has yet not been acked. \item\end{CompactList}\item 
\hypertarget{internal__comm_8c_1bb3b57523849b2a6507039940dc7495}{
void($\ast$ \hyperlink{internal__comm_8c_1bb3b57523849b2a6507039940dc7495}{f\_\-ptr\_\-rx} )(\hyperlink{structUC__MESSAGE}{UC\_\-MESSAGE})}
\label{internal__comm_8c_1bb3b57523849b2a6507039940dc7495}

\begin{CompactList}\small\item\em Function to be called when a message is recieved and should be parsed/executed. \item\end{CompactList}\item 
\hypertarget{internal__comm_8c_733ad7cf6722dfbf0c368f8e39a2cce7}{
void($\ast$ \hyperlink{internal__comm_8c_733ad7cf6722dfbf0c368f8e39a2cce7}{f\_\-ptr\_\-tx} )(char)}
\label{internal__comm_8c_733ad7cf6722dfbf0c368f8e39a2cce7}

\begin{CompactList}\small\item\em Function to be called when we wish to send a message. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
The internal communication routines. 

\begin{Desc}
\item[Author:]Mikael Larsmark, SM2WMV \end{Desc}
\begin{Desc}
\item[Date:]2010-01-25 

\begin{Code}\begin{verbatim} #include "internal_comm.c" 
\end{verbatim}
\end{Code}

 \end{Desc}


Definition in file \hyperlink{internal__comm_8c-source}{internal\_\-comm.c}.

\subsection{Function Documentation}
\hypertarget{internal__comm_8c_d9191f782631f96ebe7a5d9d846ba97b}{
\index{internal\_\-comm.c@{internal\_\-comm.c}!internal\_\-comm\_\-add\_\-tx\_\-message@{internal\_\-comm\_\-add\_\-tx\_\-message}}
\index{internal\_\-comm\_\-add\_\-tx\_\-message@{internal\_\-comm\_\-add\_\-tx\_\-message}!internal_comm.c@{internal\_\-comm.c}}
\subsubsection[{internal\_\-comm\_\-add\_\-tx\_\-message}]{\setlength{\rightskip}{0pt plus 5cm}void internal\_\-comm\_\-add\_\-tx\_\-message (unsigned char {\em command}, \/  unsigned char {\em length}, \/  char $\ast$ {\em data})}}
\label{internal__comm_8c_d9191f782631f96ebe7a5d9d846ba97b}


Add a message to the transmit queue. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em command}]The command we wish to perform \item[{\em length}]The length of the data field \item[{\em data}]The data we wish to send \end{description}
\end{Desc}


Definition at line 166 of file internal\_\-comm.c.

References UC\_\-MESSAGE::checksum, UC\_\-MESSAGE::cmd, UC\_\-MESSAGE::data, int\_\-comm\_\-tx\_\-queue\_\-add(), and UC\_\-MESSAGE::length.

Referenced by antenna\_\-ctrl\_\-deactivate\_\-outputs(), antenna\_\-ctrl\_\-send\_\-ant\_\-data\_\-to\_\-bus(), antenna\_\-ctrl\_\-send\_\-rx\_\-ant\_\-band\_\-data\_\-to\_\-bus(), antenna\_\-ctrl\_\-send\_\-rx\_\-ant\_\-data\_\-to\_\-bus(), band\_\-ctrl\_\-send\_\-band\_\-data\_\-to\_\-bus(), computer\_\-interface\_\-parse\_\-data(), main(), parse\_\-internal\_\-comm\_\-message(), ps2\_\-process\_\-key(), radio\_\-poll\_\-status(), shutdown\_\-device(), and sub\_\-menu\_\-send\_\-data\_\-to\_\-bus().\hypertarget{internal__comm_8c_038459fe5d58ddbde1ed8459d3b9bbce}{
\index{internal\_\-comm.c@{internal\_\-comm.c}!internal\_\-comm\_\-init@{internal\_\-comm\_\-init}}
\index{internal\_\-comm\_\-init@{internal\_\-comm\_\-init}!internal_comm.c@{internal\_\-comm.c}}
\subsubsection[{internal\_\-comm\_\-init}]{\setlength{\rightskip}{0pt plus 5cm}void internal\_\-comm\_\-init (void($\ast$)({\bf UC\_\-MESSAGE}) {\em func\_\-ptr\_\-rx}, \/  void($\ast$)(char) {\em func\_\-ptr\_\-tx})}}
\label{internal__comm_8c_038459fe5d58ddbde1ed8459d3b9bbce}


Initialize the internal communication. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em func\_\-ptr\_\-rx}]The function you wish to call when a new message has been recieved and should be parsed \item[{\em func\_\-ptr\_\-tx}]The function used to send data to the hardware handeling the data transmission \end{description}
\end{Desc}


Definition at line 68 of file internal\_\-comm.c.

References struct\_\-uc\_\-com::char\_\-count, struct\_\-uc\_\-com::checksum, f\_\-ptr\_\-rx, f\_\-ptr\_\-tx, struct\_\-uc\_\-com::flags, int\_\-comm\_\-rx\_\-queue\_\-dropall(), and int\_\-comm\_\-tx\_\-queue\_\-dropall().

Referenced by main().\hypertarget{internal__comm_8c_64c4f318386e5cad700f6c5e08677c6f}{
\index{internal\_\-comm.c@{internal\_\-comm.c}!internal\_\-comm\_\-poll\_\-rx\_\-queue@{internal\_\-comm\_\-poll\_\-rx\_\-queue}}
\index{internal\_\-comm\_\-poll\_\-rx\_\-queue@{internal\_\-comm\_\-poll\_\-rx\_\-queue}!internal_comm.c@{internal\_\-comm.c}}
\subsubsection[{internal\_\-comm\_\-poll\_\-rx\_\-queue}]{\setlength{\rightskip}{0pt plus 5cm}unsigned char internal\_\-comm\_\-poll\_\-rx\_\-queue (void)}}
\label{internal__comm_8c_64c4f318386e5cad700f6c5e08677c6f}


Polls the RX queue in the internal communication and calls the function defined in internal\_\-comm\_\-init. 

\begin{Desc}
\item[Returns:]1 if a message was in the buffer and got parsed, 0 if not \end{Desc}


Definition at line 91 of file internal\_\-comm.c.

References f\_\-ptr\_\-rx, int\_\-comm\_\-rx\_\-queue\_\-drop(), int\_\-comm\_\-rx\_\-queue\_\-get(), and int\_\-comm\_\-rx\_\-queue\_\-is\_\-empty().

Referenced by main().\hypertarget{internal__comm_8c_35f8e503f80c8e1188ad09c1c0dde6ec}{
\index{internal\_\-comm.c@{internal\_\-comm.c}!internal\_\-comm\_\-poll\_\-tx\_\-queue@{internal\_\-comm\_\-poll\_\-tx\_\-queue}}
\index{internal\_\-comm\_\-poll\_\-tx\_\-queue@{internal\_\-comm\_\-poll\_\-tx\_\-queue}!internal_comm.c@{internal\_\-comm.c}}
\subsubsection[{internal\_\-comm\_\-poll\_\-tx\_\-queue}]{\setlength{\rightskip}{0pt plus 5cm}unsigned char internal\_\-comm\_\-poll\_\-tx\_\-queue (void)}}
\label{internal__comm_8c_35f8e503f80c8e1188ad09c1c0dde6ec}


Polls the TX queue in the internal communication and sends the data if there is a message in the queue. 

\begin{Desc}
\item[Returns:]1 if a message was in the buffer and got sent, 0 if not \end{Desc}


Definition at line 105 of file internal\_\-comm.c.

References int\_\-comm\_\-tx\_\-queue\_\-get(), int\_\-comm\_\-tx\_\-queue\_\-is\_\-empty(), internal\_\-comm\_\-send\_\-message(), and msg\_\-not\_\-acked.

Referenced by main().\hypertarget{internal__comm_8c_b19320006eb32811d9c211f41e229f87}{
\index{internal\_\-comm.c@{internal\_\-comm.c}!internal\_\-comm\_\-send\_\-message@{internal\_\-comm\_\-send\_\-message}}
\index{internal\_\-comm\_\-send\_\-message@{internal\_\-comm\_\-send\_\-message}!internal_comm.c@{internal\_\-comm.c}}
\subsubsection[{internal\_\-comm\_\-send\_\-message}]{\setlength{\rightskip}{0pt plus 5cm}void internal\_\-comm\_\-send\_\-message ({\bf UC\_\-MESSAGE} {\em tx\_\-message})}}
\label{internal__comm_8c_b19320006eb32811d9c211f41e229f87}


Send a message to the internal communication uart. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em tx\_\-message}]The message we wish to send \end{description}
\end{Desc}


Definition at line 147 of file internal\_\-comm.c.

References UC\_\-MESSAGE::checksum, UC\_\-MESSAGE::cmd, counter\_\-tx\_\-timeout, UC\_\-MESSAGE::data, f\_\-ptr\_\-tx, UC\_\-MESSAGE::length, UC\_\-COMM\_\-MSG\_\-POSTAMBLE, and UC\_\-COMM\_\-MSG\_\-PREAMBLE.

Referenced by internal\_\-comm\_\-poll\_\-tx\_\-queue(), and internal\_\-comm\_\-resend().